﻿using System;
using System.Linq.Expressions;
using Domain.Core.Specification;
using Domain.MainModule.Entities;

namespace Domain.MainModule.Countries
{
    public class CountryISOAlpha2Specification : Specification<Country>
    {
        #region public properties

        public string ISOAlpha2
        {
            get;
            set;
        }

        #endregion

        #region constructor

        public CountryISOAlpha2Specification(string isoAlpha2)
        {
            this.ISOAlpha2 = isoAlpha2;
        }

        #endregion

        #region public methods

        public override Expression<Func<Country, bool>> SatisfiedBy()
        {
            Specification<Country> spec = new TrueSpecification<Country>();
            spec &= new DirectSpecification<Country>(t => t.IsEnabled);
            spec &= new DirectSpecification<Country>(c => c.ISO3166_Alpha2 == this.ISOAlpha2);

            return spec.SatisfiedBy();
        }

        #endregion
    }
}
